package com.example.publishDemo.Mapper;

import com.example.publishDemo.Model.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CommentMapper {

    @Insert("insert into comment(content,username,user_gravatar,u_id,r_id,p_id,target,createtime) values(#{content}, #{username}, #{user_gravatar}, #{u_id}, #{r_id}, #{p_id}, #{target}, #{createtime})")
    int save(Comment comment);

    @Select("select * from comment where r_id = #{a_id} order by createtime desc")
    List<Comment> articleComment(int a_id);

    @Delete("Delete from comment where c_id = #{c_id} and r_id = #{r_id} and p_id = #{p_id}")
    int delCommentChild(int c_id, int r_id, int p_id);

    @Delete("Delete from comment where r_id = #{r_id} and p_id = #{c_id}")
    int delCommentRoot(int r_id, int c_id);

//    ------------------其他接口的调用

    @Select("SELECT r_id FROM comment GROUP BY r_id ORDER BY count(*) DESC;")
    List<Integer> groupArticleByRid();

    @Update("update comment set user_gravatar = #{picture} where u_id=#{u_id}")
    void changeUserGravatar(String picture, int u_id);
}
